import config from '../config'

let fns = {}

/**
 * 
 * 获取我的pk
 */
fns.getMyPK = (params, success, fail) => {
  dd.showLoading();
  dd.httpRequest({

    url: config.domain + '/pk/getMyPk',
    
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}

fns.studentPkList= (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/pk/list',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}


/**
 * 
 * 裁判处理pk结果
 */
fns.updatePkResult= (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/pk/updateResult',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}
/**
 * 
 * 处理我的pk
 */
fns.updatePkStatus = (params, success, fail) => {
  dd.showLoading();
  dd.httpRequest({

    url: config.domain + '/pk/updateStatus',
    
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}

module.exports = fns